﻿using OldPlatform_to_NewPlatform.newEntity;
using OldPlatform_to_NewPlatform.oldEntity;
using System;
using System.Collections.Generic;
using System.Linq;

namespace OldPlatform_to_NewPlatform
{
    internal class EntityConvertUtil
    {
        /// <summary>
        /// 将老小时报数据映射为新小时报数据
        /// </summary>
        /// <param name="list">老小时报数据列表</param>
        /// <returns>新小时报数据列表</returns>
        internal static List<NHourRpt> ConvertHourEntity(List<HourRpt> list)
        {
            List<NHourRpt> nList = new List<NHourRpt>();
            if (list.Count == 0) { return nList; }
            // 遍历旧实体集合
            foreach (var it in list)
            {
                NHourRpt nIt = new NHourRpt
                {
                    Slot_id = it.Slot_id.Trim(),
                    Record_date = it.Record_date,
                    Record_hour = it.Record_hour,
                    Electric = (decimal)Math.Round(it.Electric, 1),
                    Volt_set = (decimal)Math.Round(it.Volt_set / 1000, 3),
                    Work_volt = (decimal)Math.Round(it.Volt_work, 3),
                    Volt_avg = (decimal)Math.Round(it.Volt_avg, 3),
                    Nb_interval_set = it.Nb_interval_set,
                    Nb_total = (decimal)Math.Round(it.Nb_num, 1),
                    Nb_times = it.Nb_times,
                    Alumina_nb_total = 0,
                    Alumina_nb_times = it.Small_nb_times + it.Manual_small_nb_times +
                    (it.Big_nb_times + it.Manual_big_nb_times) * 2,
                    Nb_owe_times = it.Nb_owe_times,
                    Nb_over_times = it.Nb_over_times,
                    Auto_small_nb_times = it.Small_nb_times,
                    Auto_big_nb_times = it.Big_nb_times,
                    Manual_small_nb_times = it.Manual_small_nb_times,
                    Manual_big_nb_times = it.Manual_big_nb_times,
                    Fluoride_salt_nb_total = (decimal)Math.Round(it.Fu_salt_value, 1),
                    Fluoride_salt_nb_times = it.Fu_salt_times + it.Manual_fu_salt_times,
                    Auto_fluoride_salt_nb_times = it.Fu_salt_times,
                    Manual_fluoride_salt_nb_times = it.Manual_fu_salt_times,
                    Exception_volt_avg = (decimal)Math.Round(it.Exception_volt_avg, 3),
                    Exception_volt_duration = (decimal)Math.Round(it.Exception_volt_interval, 1),
                    Avg_vibration = (decimal)Math.Round(it.Vibration_value, 3),
                    Vibration_serious_duration = (decimal)Math.Round(it.Vibration_interval, 1),
                    Avg_swing = (decimal)Math.Round(it.Swing_value, 3),
                    Swing_serious_duration = (decimal)Math.Round(it.Swing_interval, 1),
                    Sum_power_waste = (decimal)Math.Round(it.Pow_waste, 1),
                    Exception_power_waste = (decimal)Math.Round(it.Exception_volt_avg * it.Electric * it.Exception_volt_interval / 60, 1),
                    Out_al_time = "",
                    Change_anode_time = "",
                    Auto_anode_up_times = it.Auto_pole_up_times,
                    Auto_anode_down_times = it.Auto_pole_down_times,
                    Manual_anode_up_times = it.Manual_pole_up_times,
                    Manual_anode_down_times = it.Manual_pole_dwon_times
                };
                if (it.Nb_times > 0)
                {
                    var singleNum = it.Nb_num / it.Nb_times;
                    nIt.Alumina_nb_total = (decimal)Math.Round(nIt.Alumina_nb_times * singleNum, 1);
                }
                List<string> outAlList = new List<string>();
                if (it.Out_al_first_time != null && it.Out_al_first_time.ToString() != "0001/1/1 0:00:00")
                {
                    outAlList.Add(it.Out_al_first_time.ToString("HH:mm:ss"));
                }
                if (it.Out_al_second_time != null && it.Out_al_second_time.ToString() != "0001/1/1 0:00:00")
                {
                    outAlList.Add(it.Out_al_second_time.ToString("HH:mm:ss"));
                }
                if (it.Out_al_third_time != null && it.Out_al_third_time.ToString() != "0001/1/1 0:00:00")
                {
                    outAlList.Add(it.Out_al_third_time.ToString("HH:mm:ss"));
                }
                if (outAlList.Count > 0)
                {
                    nIt.Out_al_time = string.Join(" | ", outAlList);
                }
                if (it.Chang_pole_time != null && it.Chang_pole_time.ToString() != "0001/1/1 0:00:00")
                {
                    nIt.Change_anode_time = it.Chang_pole_time.ToString("HH:mm:ss");
                }
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 将老班报数据映射为新班报数据
        /// </summary>
        /// <param name="list">老班报数据列表</param>
        /// <returns>新班报数据列表</returns>
        internal static List<NShiftRpt> ConvertShiftEntity(List<ShiftRpt> list)
        {
            List<NShiftRpt> nList = new List<NShiftRpt>();
            if (list == null | list.Count == 0) { return nList; }
            foreach (var it in list)
            {
                NShiftRpt nIt = new NShiftRpt
                {
                    Slot_id = it.Slot_id.Trim(),
                    Record_date = it.Record_date,
                    Shift_id = it.Shift_time_id,
                    Status = it.Status,
                    Electric = (decimal)Math.Round(it.Electric, 1),
                    Volt_set = (decimal)Math.Round(it.Volt_set / 1000, 3),
                    Work_volt = (decimal)Math.Round(it.Volt_work, 3),
                    Volt_avg = (decimal)Math.Round(it.Volt_avg, 3),
                    Nb_interval_set = it.Nb_interval_set,
                    Nb_total = (decimal)Math.Round(it.Nb_num, 1),
                    Nb_times = it.Nb_times,
                    Alumina_nb_total = 0,
                    Alumina_nb_times = it.Small_nb_times + it.Manual_small_nb_times +
                    (it.Big_nb_times + it.Manual_big_nb_times) * 2,
                    Nb_owe_times = it.Nb_own_times,
                    Nb_over_times = it.Nb_over_times,
                    Auto_small_nb_times = it.Small_nb_times,
                    Auto_big_nb_times = it.Big_nb_times,
                    Manual_small_nb_times = it.Manual_small_nb_times,
                    Manual_big_nb_times = it.Manual_big_nb_times,
                    Fluoride_salt_nb_total = (decimal)Math.Round(it.Fu_salt_value, 1),
                    Fluoride_salt_nb_times = it.Fu_salt_times + it.Manual_fu_salt_times,
                    Auto_fluoride_salt_nb_times = it.Fu_salt_times,
                    Manual_fluoride_salt_nb_times = it.Manual_fu_salt_times,
                    Exception_volt_avg = (decimal)Math.Round(it.Exception_volt_avg, 3),
                    Exception_volt_duration = (decimal)Math.Round(it.Exception_volt_interval, 1),
                    Avg_vibration = (decimal)Math.Round(it.Vibration_value, 3),
                    Vibration_serious_duration = (decimal)Math.Round(it.Vibration_interval, 1),
                    Avg_swing = (decimal)Math.Round(it.Swing_value, 3),
                    Swing_serious_duration = (decimal)Math.Round(it.Swing_interval, 1),
                    Sum_power_waste = (decimal)Math.Round(it.Pow_waste, 1),
                    Exception_power_waste = (decimal)Math.Round(it.Exception_volt_avg * it.Electric * it.Exception_volt_interval / 60, 1),
                    Out_al_time = "",
                    Change_anode_time = "",
                    Auto_anode_up_times = it.Auto_pole_up_times,
                    Auto_anode_down_times = it.Auto_pole_down_times,
                    Manual_anode_up_times = it.Manual_pole_up_times,
                    Manual_anode_down_times = it.Manual_pole_dwon_times
                };
                if (it.Nb_times > 0)
                {
                    var singleNum = it.Nb_num / it.Nb_times;
                    nIt.Alumina_nb_total = (decimal)Math.Round(nIt.Alumina_nb_times * singleNum, 1);
                }
                List<string> outAlList = new List<string>();
                if (it.Out_al_first_time != null && it.Out_al_first_time.ToString() != "0001/1/1 0:00:00")
                {
                    outAlList.Add(it.Out_al_first_time.ToString("HH:mm:ss"));
                }
                if (it.Out_al_second_time != null && it.Out_al_second_time.ToString() != "0001/1/1 0:00:00")
                {
                    outAlList.Add(it.Out_al_second_time.ToString("HH:mm:ss"));
                }
                if (it.Out_al_third_time != null && it.Out_al_third_time.ToString() != "0001/1/1 0:00:00")
                {
                    outAlList.Add(it.Out_al_third_time.ToString("HH:mm:ss"));
                }
                if (outAlList.Count > 0)
                {
                    nIt.Out_al_time = string.Join(" | ", outAlList);
                }
                if (it.Chang_pole_time != null && it.Chang_pole_time.ToString() != "0001/1/1 0:00:00")
                {
                    nIt.Change_anode_time = it.Chang_pole_time.ToString("HH:mm:ss");
                }
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 将老日报数据映射为新日报数据
        /// </summary>
        /// <param name="list">老日报数据列表</param>
        /// <returns>新班报数据列表</returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static List<NDayRpt> ConvertDayEntity(List<DayRpt> list)
        {
            List<NDayRpt> nList = new List<NDayRpt>();
            if (list == null | list.Count == 0)
            {
                return nList;
            }
            foreach (var it in list)
            {
                NDayRpt nIt = new NDayRpt
                {
                    Slot_id = it.Slot_id.Trim(),
                    Record_date = it.Record_date,
                    Status = it.Status,
                    Electric = (decimal)Math.Round(it.Electric, 1),
                    Volt_set = (decimal)Math.Round(it.Volt_set / 1000, 3),
                    Work_volt = (decimal)Math.Round(it.Volt_work, 3),
                    Volt_avg = (decimal)Math.Round(it.Volt_avg, 3),
                    Nb_interval_set = it.Nb_interval_set,
                    Nb_total = (decimal)Math.Round(it.Nb_num, 1),
                    Nb_times = it.Nb_times,
                    Alumina_nb_total = 0,
                    Alumina_nb_times = it.Small_nb_times + it.Manual_small_nb_times +
                    (it.Big_nb_times + it.Manual_big_nb_times) * 2,
                    Nb_owe_times = it.Nb_own_times,
                    Nb_over_times = it.Nb_over_times,
                    Auto_small_nb_times = it.Small_nb_times,
                    Auto_big_nb_times = it.Big_nb_times,
                    Manual_small_nb_times = it.Manual_small_nb_times,
                    Manual_big_nb_times = it.Manual_big_nb_times,
                    Fluoride_salt_nb_total = (decimal)Math.Round(it.Fu_salt_value, 1),
                    Fluoride_salt_nb_times = it.Fu_salt_times + it.Manual_fu_salt_times,
                    Auto_fluoride_salt_nb_times = it.Fu_salt_times,
                    Manual_fluoride_salt_nb_times = it.Manual_fu_salt_times,
                    Exception_volt_avg = (decimal)Math.Round(it.Exception_volt_avg, 3),
                    Exception_volt_duration = (decimal)Math.Round(it.Exception_volt_interval, 1),
                    Avg_vibration = (decimal)Math.Round(it.Vibration_value, 3),
                    Vibration_serious_duration = (decimal)Math.Round(it.Vibration_interval, 1),
                    Avg_swing = (decimal)Math.Round(it.Swing_value, 3),
                    Swing_serious_duration = (decimal)Math.Round(it.Swing_interval, 1),
                    Sum_power_waste = (decimal)Math.Round(it.Pow_waste, 1),
                    Exception_power_waste = (decimal)Math.Round(it.Exception_volt_avg * it.Electric * it.Exception_volt_interval / 60, 1),
                    Out_al_time = "",
                    Change_anode_time = "",
                    Auto_anode_up_times = it.Auto_pole_up_times,
                    Auto_anode_down_times = it.Auto_pole_down_times,
                    Manual_anode_up_times = it.Manual_pole_up_times,
                    Manual_anode_down_times = it.Manual_pole_dwon_times
                };
                if (it.Nb_times > 0)
                {
                    var singleNum = it.Nb_num / it.Nb_times;
                    nIt.Alumina_nb_total = (decimal)Math.Round(nIt.Alumina_nb_times * singleNum, 1);
                }
                List<string> outAlList = new List<string>();
                if (it.Out_al_first_time != null && it.Out_al_first_time.ToString() != "0001/1/1 0:00:00")
                {
                    outAlList.Add(it.Out_al_first_time.ToString("HH:mm:ss"));
                }
                if (it.Out_al_second_time != null && it.Out_al_second_time.ToString() != "0001/1/1 0:00:00")
                {
                    outAlList.Add(it.Out_al_second_time.ToString("HH:mm:ss"));
                }
                if (it.Out_al_third_time != null && it.Out_al_third_time.ToString() != "0001/1/1 0:00:00")
                {
                    outAlList.Add(it.Out_al_third_time.ToString("HH:mm:ss"));
                }
                if (outAlList.Count > 0)
                {
                    nIt.Out_al_time = string.Join(" | ", outAlList);
                }
                if (it.Chang_pole_time != null && it.Chang_pole_time.ToString() != "0001/1/1 0:00:00")
                {
                    nIt.Change_anode_time = it.Chang_pole_time.ToString("HH:mm:ss");
                }
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 将老工艺数据映射为新工艺数据
        /// </summary>
        /// <param name="list">老工艺数据列表</param>
        /// <returns>新工艺数据列表</returns>
        internal static List<NProcessData> ConvertProcessEntity(List<ProcessData> list)
        {
            List<NProcessData> nList = new List<NProcessData>();
            if (list == null | list.Count == 0) { return nList; }
            foreach (var it in list)
            {
                NProcessData nIt = new NProcessData
                {
                    Slot_id = it.Slot_id.Trim(),
                    Record_date = it.Record_date,
                    Al_temp = (decimal)Math.Round(it.Temp, 1),
                    Base_al_level = (decimal)Math.Round(it.Base_al_level, 1),
                    Al_level = (decimal)Math.Round(it.Al_level, 1),
                    Electrolyte_level = (decimal)Math.Round(it.Electrolyte_level, 1),
                    Slot_temp = (decimal)Math.Round(it.Slot_temp, 1),
                    Cry_add = (decimal)Math.Round(it.Cry_add, 1),
                    Cry_temp = (decimal)Math.Round(it.Cry_temp, 1),
                    Press_drop = (decimal)Math.Round((it.Press_drop_aa + it.Press_drop_bb) / 2, 1),
                    Insulation_thick = (decimal)Math.Round(it.Insulation_thick, 1),
                    Polar_distance = (decimal)Math.Round(it.Polar_distance, 1),
                    Anode_piece_id = "",
                    Advice_out_al = (decimal)Math.Round(it.Advice_out_al, 1),
                    Al_suction = (decimal)Math.Round(it.Total_al, 1),
                    Ana_fe = (decimal)Math.Round(it.Ana_fe, 3),
                    Ana_si = (decimal)Math.Round(it.Ana_si, 3),
                    Ana_ca = (decimal)Math.Round(it.Ana_ca, 3),
                    Ana_mg = (decimal)Math.Round(it.Ana_mg, 3),
                    Al_quality = (decimal)Math.Round(it.Al_quality, 2),
                    Al_grade = "",
                    Molecular_ratio = (decimal)Math.Round(it.Molertio, 2),
                    Ana_al2o3 = (decimal)Math.Round(it.Ana_al2_o3, 2),
                    Ana_alf = (decimal)Math.Round(it.Ana_alf, 2),
                    Ana_caf = (decimal)Math.Round(it.Ana_caf, 3),
                    Ana_mgf = (decimal)Math.Round(it.Ana_maf, 3),
                    Ana_lif = (decimal)Math.Round(it.Ana_lif, 3),
                    Ana_kf = (decimal)Math.Round(it.Ana_kf, 3)
                };
                if (it.Pole_piece_id != 0)
                {
                    nIt.Anode_piece_id = ((int)it.Pole_piece_id).ToString();
                }
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 将老效应数据映射为新效应数据
        /// </summary>
        /// <param name="list">老效应数据列表</param>
        /// <returns>新效应数据列表</returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static List<NEffectData> ConvertEffectEntity(List<EffectData> list)
        {
            List<NEffectData> nList = new List<NEffectData>();
            if (list.Count == 0) { return nList; }
            foreach (var it in list)
            {
                NEffectData nIt = new NEffectData
                {
                    Slot_id = it.Slot_id,
                    Record_date = it.Record_date,
                    Effect_duration = it.Continue_time,
                    Effect_volt_max = it.Volt_max,
                    Effect_volt_avg = it.Volt_avg,
                    Effect_power_waste = it.Power_waste,
                    Effect_type = (it.Continue_time > 50) ? 1 : 2
                };
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 将老故障数据映射到新故障数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static List<NFaultData> ConvertFaultEntity(List<FaultData> list)
        {
            List<NFaultData> nList = new List<NFaultData>();
            if (list.Count == 0) { return nList; }
            foreach (var it in list)
            {
                NFaultData nIt = new NFaultData
                {
                    Slot_id = it.Slot_id,
                    Record_date = it.Record_date,
                    Msg = it.Msg
                };
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 将老人工操作数据映射为新人工操作数据
        /// </summary>
        /// <param name="list">老人工操作数据列表</param>
        /// <returns>新人工操作数据列表</returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static List<NOperateData> ConvertOperateEntity(List<OperateData> list)
        {
            List<NOperateData> nList = new List<NOperateData>();
            if (list.Count == 0) { return nList; }
            foreach (var it in list)
            {
                NOperateData nIt = new NOperateData
                {
                    Slot_id = it.Slot_id,
                    Record_date = it.Operate_date,
                    Msg = it.Operate_msg
                };
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 将老参数修改记录映射为新参数修改记录
        /// </summary>
        /// <param name="list">老参数修改记录列表</param>
        /// <returns>新参数修改记录列表</returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static List<NParamChangeData> ConvertParamChangeEntity(List<ParamChangeData> list)
        {
            List<NParamChangeData> nList = new List<NParamChangeData>();
            if (list.Count == 0) { return nList; }
            foreach (var it in list)
            {
                NParamChangeData nIt = new NParamChangeData
                {
                    Slot_id = it.Slot_id,
                    Record_date = it.Record_date,
                    Change_type = it.Change_type,
                    Origin_value = it.Origin_value.ToString(),
                    Modify_value = it.Modify_value.ToString(),
                    User_name = it.User_name,
                    Ip_address = ""
                };
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 将老历史曲线数据映射为新历史曲线数据
        /// </summary>
        /// <param name="list">老历史曲线数据列表</param>
        /// <returns>新历史曲线数据列表</returns>
        internal static List<NHistoryData> ConvertHistoryEntity(List<HistoryData> list)
        {
            foreach (var it in list)
            {
                it.Date = DateTimeUtils.OldTimeToNewtime(it.Date);
            }
            List<NHistoryData> nList = new List<NHistoryData>();
            if (list == null && list.Count == 0) { return nList; }
            // 获取最后一条数据的日期，作为今天的开始时间
            DateTime todayStartTime = list[list.Count - 1].Date.Date;
            // 创建新的历史数据集合
            List<NHistoryData> nsList = new List<NHistoryData>();
            // 循环遍历数据，判断数据是否连续，如果不连续，需要补全数据
            for (int i = 0; i < list.Count; i++)
            {
                // 获取数据转换后的日期
                DateTime convertTime = DateTimeUtils.OldTimeToNewtime(list[i].Date);
                // 处理第一条数据
                if (i == 0)
                {
                    // 判断日期时间是否大于等于实际第一条数据的日期时间，需要往前补数据
                    if (convertTime >= todayStartTime.AddSeconds(5))
                    {
                        // 计算当前数据的日期与第一条数据的日期的差值
                        var diff = (convertTime - todayStartTime.AddSeconds(5)).TotalSeconds;
                        // 计算需要补的数据的数量
                        int count = (int)diff / 10;
                        if (count >= 0)
                        {
                            // 循环补数据
                            for (int j = count; j > 0; j--)
                            {
                                var data = ConvertToNewHistory(list[i]);
                                data.Record_time = data.Record_time.AddSeconds(-10 * j);
                                if (data.Record_time >= todayStartTime.AddSeconds(5))
                                { nList.Add(data); }
                            }
                        }
                    }
                }
                // 处理中间数据
                else
                {
                    // 判断当前数据的日期与前一条数据的日期的差值
                    var diff = (convertTime - ConvertToNewHistory(list[i - 1]).Record_time).TotalSeconds;
                    // 如果相差大于10秒，需要从上一个数据往后补数据
                    int count = (int)diff / 10;
                    if (count > 0)
                    {
                        // 循环补数据
                        for (int j = 1; j <= count; j++)
                        {
                            if (j == count)
                            {
                                // 自身当前数据
                                var currDdata = ConvertToNewHistory(list[i]);
                                if (currDdata.Record_time >= todayStartTime.AddSeconds(5))
                                {
                                    nList.Add(currDdata);
                                }
                            }
                            else
                            {
                                var preData = ConvertToNewHistory(list[i - 1]);
                                preData.Record_time = preData.Record_time.AddSeconds(10 * j);
                                if (preData.Record_time >= todayStartTime.AddSeconds(5))
                                { nList.Add(preData); }
                            }
                        }
                    }
                }
                // 处理最后一条数据
                if (i == list.Count - 1)
                {
                    // 最后一条数据与实际最后一条数据的时间差值
                    var diff = (todayStartTime.AddDays(1).AddSeconds(-5) - convertTime).TotalSeconds;
                    // 计算需要补的数据的数量
                    int count = (int)diff / 10;
                    if (count > 0)
                    {
                        // 循环补数据
                        for (int j = 1; j <= count; j++)
                        {
                            var data = ConvertToNewHistory(list[i]);
                            data.Record_time = data.Record_time.AddSeconds(10 * j);
                            nList.Add(data);
                        }
                    }
                }
            }
            nList = nList.GroupBy(it => it.Record_time).Select(it => it.First()).ToList();
            return nList;
        }

        private static NHistoryData ConvertToNewHistory(HistoryData it)
        {
            return new NHistoryData
            {
                Slot_id = it.Slot_id,
                Record_time = DateTimeUtils.OldTimeToNewtime(it.Date),
                Electric = (decimal)Math.Round(it.Electric, 2),
                Volt = (decimal)Math.Round(it.Volt, 3),
                Volt_set = (decimal)Math.Round(it.Volt_set / 1000.0, 3),
                Max_control_volt = (decimal)Math.Round(it.Volt_upper_limit, 3),
                Min_control_volt = (decimal)Math.Round(it.Volt_lower_limit, 3),
                Resistance = (decimal)Math.Round(it.Resistance, 3),
                Filter_res = (decimal)Math.Round(it.Filter_res, 3),
                Smooth_res = (decimal)Math.Round(it.Smooth_res, 3),
                Vibration = (int)it.Vibration,
                Swing = (int)it.Swing,
                Acc_slope = (int)it.Accsloper,
                Nb_interval_real = it.Real_nb_interval,
                Nb_interval_set = it.Set_nb_interval,
                Nb_mode = it.Nb_mode,
                Nb_status = (short)it.Bank_state,
                Fluoride_salt_nb_status = (short)it.Fu_salt,
                Effect_status = (short)it.Reaction,
                Effect_ago = it.Reaction_interval,
                Control_status = 0,
                Anode_move_status = (short)it.Pole_up_down,
                Out_al_status = (short)it.Out_al,
                Change_anode_status = (short)it.Change_pole,
                Edge_process_status = (short)it.Side_process,
                Raise_bus_status = (short)it.Bus_put_up,
                Purely_manual_status = (short)it.Pure_man_operation
            };
        }

        private static NHistoryData NewHistory(HistoryData it)
        {
            return new NHistoryData
            {
                Slot_id = it.Slot_id,
                Record_time = DateTimeUtils.OldTimeToNewtime(it.Date),
                Electric = (decimal)Math.Round(it.Electric, 2),
                Volt = (decimal)Math.Round(it.Volt, 3),
                Volt_set = (decimal)Math.Round(it.Volt_set, 3),
                Max_control_volt = (decimal)Math.Round(it.Volt_upper_limit, 3),
                Min_control_volt = (decimal)Math.Round(it.Volt_lower_limit, 3),
                Resistance = (decimal)Math.Round(it.Resistance, 3),
                Filter_res = (decimal)Math.Round(it.Filter_res, 3),
                Smooth_res = (decimal)Math.Round(it.Smooth_res, 3),
                Vibration = (int)it.Vibration,
                Swing = (int)it.Swing,
                Acc_slope = (int)it.Accsloper,
                Nb_interval_real = it.Real_nb_interval,
                Nb_interval_set = it.Set_nb_interval,
                Nb_mode = it.Nb_mode,
                Nb_status = (short)it.Bank_state,
                Fluoride_salt_nb_status = (short)it.Fu_salt,
                Effect_status = (short)it.Reaction,
                Effect_ago = it.Reaction_interval,
                Control_status = 0,
                Anode_move_status = (short)it.Pole_up_down,
                Out_al_status = (short)it.Out_al,
                Change_anode_status = (short)it.Change_pole,
                Edge_process_status = (short)it.Side_process,
                Raise_bus_status = (short)it.Bus_put_up,
                Purely_manual_status = (short)it.Pure_man_operation
            };
        }

        /// <summary>
        /// 将老地址参数数据映射为新地址参数数据
        /// </summary>
        /// <param name="list">老地址参数数据列表</param>
        /// <returns>新地址参数数据列表</returns>
        internal static List<NAddressParam> ConvertAddressParamEntity(List<AddressParam> list)
        {
            List<NAddressParam> nList = new List<NAddressParam>();
            if (list.Count == 0) { return nList; }
            foreach (var it in list)
            {
                NAddressParam nIt = new NAddressParam()
                {
                    Slot_id = it.Slot_id,
                    Address_bit = it.Address_bit_head,
                    Address_value = it.Value,
                    High_bit_value = it.High_value,
                    Low_bit_value = it.Low_value
                };
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 将老生产参数数据映射为新生产参数数据
        /// </summary>
        /// <param name="list">老生产参数数据列表</param>
        /// <returns>新生产参数数据列表</returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static List<NProductParam> ConvertProductParamEntity(List<ProductParam> list)
        {
            List<NProductParam> nList = new List<NProductParam>();
            if (list.Count == 0) { return nList; }
            foreach (var it in list)
            {
                NProductParam nIt = new NProductParam()
                {
                    Slot_id = it.Slot_id,
                    Volt_set = it.Volt_set,
                    Nb_interval = it.Nb_interval,
                    Fluoride_salt_total = it.F_salt_num,
                    Nb_status = it.Nb_status,
                    Nb_control_time = it.Nb_control_time,
                    Rc_status = it.Rc_status,
                    Rc_control_time = it.Rc_control_time,
                    Volt_sensitive_area_up = it.Sensitive_area_up,
                    Volt_sensitive_area_down = it.Sensitive_area_down,
                    Flicker_effect_judge = it.Flicker_effect_interval,
                    Effect_interval = it.Effect_interval,
                    Effect_wait_time = it.Effect_wait_interval
                };
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 将老系统参数数据映射为新系统参数数据
        /// </summary>
        /// <param name="list">老系统参数数据列表</param>
        /// <returns>新系统参数数据列表</returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static List<NSystemParam> ConvertSystemParamEntity(List<SystemParam> list)
        {
            List<NSystemParam> nList = new List<NSystemParam>();
            if (list.Count == 0) { return nList; }
            foreach (var it in list)
            {
                NSystemParam nIt = new NSystemParam()
                {
                    Slot_id = it.Slot_id,
                    Standard_series_electric = it.Norm_series_electricity,
                    Base_owe_period = it.Base_owe_period,
                    Base_norm_period = it.Base_norm_period,
                    Base_over_period = it.Base_over_period,
                    Effect_over_period = it.Effect_over_period,
                    Max_over_period = it.Max_over_period,
                    Init_nb_period = it.Nb_init_time,
                    Capacity = it.Capacity,
                    Alternate_nb_and_effect_process_times = it.Alternate_nb_and_reaction_process_times,
                    Shell_break_and_nb_interval = it.Crust_breaker_and_nb_interval,
                    Nb_action_time = it.Nb_action_time,
                    Shell_break_action_time = it.Crust_breaker_action_time,
                    Out_al_add_volt = it.Out_al_additional_volt,
                    Change_anode_add_volt = it.Change_pole_additional_volt,
                    Edge_process_add_volt = it.Edge_process_additional_volt,
                    Out_al_add_volt_time = it.Out_al_additional_volt_time,
                    Change_anode_add_volt_time = it.Change_pole_additional_volt_time,
                    Edge_process_add_volt_time = it.Edge_process_additional_volt_time,
                    Vibration_add_volt = it.Vibration_additional_volt,
                    Swing_add_volt = it.Swing_additional_volt,
                    Ae_rc_control = it.Ae_rc_control,
                    Max_adjustable_volt = it.Volt_unregulated_upper,
                    Min_adjustable_volt = it.Volt_unregulated_lower,
                    Min_anode_move_period = it.Min_anode_move_period,
                    Max_add_volt = it.Max_over_period,
                    Max_anode_move_period = it.Max_auto_anode_move_time,
                    Min_out_al_time = it.Out_al_min_valid_time,
                    Max_out_al_time = it.Out_al_max_valid_time,
                    Min_change_anode_time = it.Change_pole_min_valid_time,
                    Max_change_anode_time = it.Change_pole_max_valid_time,
                    Min_edge_process_time = it.Edge_process_min_valid_time,
                    Max_edge_process_time = it.Edge_process_max_valid_time,
                    Change_anode_and_stop_nb_time = it.Change_pole_and_stop_feed_valid_time,
                    Min_auto_nb_electric = it.Nb_electricity_lower,
                    Max_auto_nb_electric = it.Nb_electricity_upper,
                    Vibration_judge = it.Vibration_not_standard,
                    Vibration_serious_judge = it.Vibration_hard_standard,
                    Swing_judge = it.Swing_not_standard,
                    Swing_serious_judge = it.Swing_hard_standard,
                    Out_al_and_stop_nb_time = it.Out_al_and_stop_feed_valid_time,
                    Edge_process_and_stop_nb_time = it.Edge_process_and_stop_feed_valid_time
                };
                nList.Add(nIt);
            }
            return nList;
        }

        /// <summary>
        /// 老打壳深度参数数据映射为新打壳深度参数数据
        /// </summary>
        /// <param name="list">老打壳深度参数数据列表</param>
        /// <returns>新打壳深度参数数据列表</returns>
        /// <exception cref="NotImplementedException"></exception>
        internal static List<NDepthParam> ConvertDepthParamEntity(List<DepthParam> list)
        {
            List<NDepthParam> nList = new List<NDepthParam>();
            if (list.Count == 0) { return nList; }
            foreach (var it in list)
            {
                NDepthParam nIt = new NDepthParam
                {
                    Slot_id = it.Slot_id,
                    Break_percent = ""
                };
                List<string> strList = new List<string>();
                if (it.Depth_first > 0)
                {
                    strList.Add(it.Depth_first.ToString());
                }
                if (it.Depth_Second > 0)
                {
                    strList.Add(it.Depth_Second.ToString());
                }
                if (it.Depth_third > 0)
                {
                    strList.Add(it.Depth_third.ToString());
                }
                if (it.Depth_fourth > 0)
                {
                    strList.Add(it.Depth_fourth.ToString());
                }
                if (it.Depth_fifth > 0)
                {
                    strList.Add(it.Depth_fifth.ToString());
                }
                if (it.Depth_sixth > 0)
                {
                    strList.Add(it.Depth_sixth.ToString());
                }
                if (it.Depth_seventh > 0)
                {
                    strList.Add(it.Depth_seventh.ToString());
                }
                if (it.Depth_eighth > 0)
                {
                    strList.Add(it.Depth_eighth.ToString());
                }
                if (strList.Count > 0)
                {
                    nIt.Break_depth_set = string.Join(",", strList);
                }
                nList.Add(nIt);
            }
            return nList;
        }
    }
}